﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CHATCENTRAL.ENTITIES;
using Interfaces;
using ChatInterfaces;
using CHATCENTRAL.MAPPERS;
using CHATCENTRAL.Interfaces.Entities;

namespace CHATCENTRAL
{
    public class StartUp
    {
        public IChatCentralViewer view { get; set; }

        private static StartUp inst;

        public static StartUp GetInst()
        {
            if (inst == null)
                inst = new StartUp();

            return inst;
        }

        private StartUp() { }

        public void SetStartUp()
        {
            view.logTemas(AddTemas());
            view.logUsers(AddUsers());
            view.logUsersTemas(AddTemaUser());
        }

        private IEnumerable<IClient> AddUsers()
        {
            ClientMapper.GetInstance().AddUser(new Client { pwd = "123", username = "Hugo", IsOnline = false, Lang = "pt", baseAddress = "http://localhost:8731/ClienteService/" });
            ClientMapper.GetInstance().AddUser(new Client { pwd = "123456", username = "Paulo", IsOnline = false, Lang = "en", baseAddress = "http://localhost:8732/ClienteService/" });
            ClientMapper.GetInstance().AddUser(new Client { pwd = "123", username = "PC", IsOnline = false, Lang = "fr", baseAddress = "http://localhost:8734/ClienteService/" });
            ClientMapper.GetInstance().AddUser(new Client { pwd = "123456", username = "LFV", IsOnline = false, Lang = "pt" });

            return ClientMapper.GetInstance().GetAllUsers();
        }

        private IEnumerable<ITema> AddTemas()
        {
            TemaMapper.GetInstance().AddTema(new Tema { subject = "Desporto" });
            TemaMapper.GetInstance().AddTema(new Tema { subject = "Politica" });
            TemaMapper.GetInstance().AddTema(new Tema { subject = "Finanças" });
            TemaMapper.GetInstance().AddTema(new Tema { subject = "Musica" });
            
            return TemaMapper.GetInstance().GetAllTemas();
        }

        private IEnumerable<ITema_User> AddTemaUser()
        {
            ITema_User tu = new Tema_User();
            tu.tema = TemaMapper.GetInstance().GetTema("Desporto");
            tu.user = ClientMapper.GetInstance().GetUser("Hugo", "123");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu);

            ITema_User tu2 = new Tema_User();
            tu2.tema = TemaMapper.GetInstance().GetTema("Musica");
            tu2.user = ClientMapper.GetInstance().GetUser("Hugo", "123");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu2);

            ITema_User tu3 = new Tema_User();
            tu3.tema = TemaMapper.GetInstance().GetTema("Politica");
            tu3.user = ClientMapper.GetInstance().GetUser("Paulo", "123456");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu3);

            ITema_User tu4 = new Tema_User();
            tu4.tema = TemaMapper.GetInstance().GetTema("Finanças");
            tu4.user = ClientMapper.GetInstance().GetUser("Paulo", "123456");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu4);

            ITema_User tu5 = new Tema_User();
            tu5.tema = TemaMapper.GetInstance().GetTema("Musica");
            tu5.user = ClientMapper.GetInstance().GetUser("Paulo", "123456");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu5);

            ITema_User tu6 = new Tema_User();
            tu6.tema = TemaMapper.GetInstance().GetTema("Finanças");
            tu6.user = ClientMapper.GetInstance().GetUser("PC", "123");
            Tema_User_Mapper.GetInstance().AddTemaUser(tu6);

            return Tema_User_Mapper.GetInstance().GetAllTemaUser();
        }
    }
}
